package com.woniu.cms.lease.core.service.impl;

import com.woniu.cms.lease.core.VO.StorageVO;
import com.woniu.cms.lease.core.entity.LeaseManage;
import com.woniu.cms.lease.core.entity.LeaseStorage;
import com.woniu.cms.lease.core.mapper.LeaseStorageMapper;
import com.woniu.cms.lease.core.service.ILeaseManageService;
import com.woniu.cms.lease.core.mapper.LeaseManageMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author romantic sheep
 * @since 2022-09-18
 */
@Service
public class LeaseManageServiceImpl extends ServiceImpl<LeaseManageMapper, LeaseManage> implements ILeaseManageService {

    @Autowired
    private LeaseStorageServiceImpl leaseStorageService;


    @Autowired
    private LeaseManageServiceImpl leaseManageService;

    @Autowired
    private LeaseManageMapper leaseManageMapper;




    @Override
    //查询
    public List<LeaseManage> queryAll() {
        List<LeaseManage> list = leaseManageService.list();
        return list;
    }

    //新增仪表申请单
    @Override
    public int add(LeaseManage leaseManage) {
        int insert = leaseManageMapper.insert(leaseManage);
        return insert;
    }


    //查询vo对象
    @Override
    public List<StorageVO> alll() {
        List<LeaseStorage> all = leaseStorageService.all();
        List<StorageVO> collect = all.stream().filter(a -> a.getCondition() == 0).map(e -> {
            StorageVO storageVO = new StorageVO();
            BeanUtils.copyProperties(e, storageVO);
            return storageVO;
        }).collect(Collectors.toList());
        System.out.println("collect = " + collect);
        return collect;
    }

    @Override
    //修改
    public boolean modify(LeaseManage leaseManage) {
        boolean i = leaseManageService.updateById(leaseManage);
        return i;
    }

    //修改归还状态,生成当前归还时间
    @Override
    public int returne(int id) {
        return leaseManageMapper.returne(id);
    }

    //租金合计
    @Override
    public Integer TotalRent(Integer id) {
        return leaseManageMapper.TotalRent(id);
    }


}
